package leetcode.listnode;

import java.util.ArrayList;
import java.util.List;

public class BinaryTreePaths {

    private List<String> result = new ArrayList<>();

    private void search(String string, TreeNode node) {
        if (node != null && node.left == null && node.right == null) {
            result.add(string);
            return;
        }

        if (node.left != null) {
            search(string + "->" + node.left.val, node.left);
        }

        if (node.right != null) {
            search(string + "->" + node.right.val, node.right);
        }
    }

    public List<String> binaryTreePaths(TreeNode root) {
        search(String.valueOf(root.val), root);
        return result;
    }

}
